package com.wn.login.viewmodel

import com.wn.common.model.User
import com.wn.login.repository.LoginRepository
import com.wn.network.viewmodel.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

/**
 * @Author: wn
 * @Date: 2025/7/1 17:20
 * @Description: 登录 viewModel
 */
@HiltViewModel
class LoginViewModel @Inject constructor(private val repository: LoginRepository) :
  BaseViewModel() {
  /**
   * 登录
   * @param username String
   * @param password String
   * @return StateFlow<User?>
   */
  fun login(username: String, password: String): StateFlow<User?> =
    callBaseRequest(
      { scope, errorCall, showLoading ->
        repository.login(
          scope,
          errorCall,
          showLoading,
          username,
          password
        )
      },
      true
    )

  /**
   * 注册
   * @param username String
   * @param password String
   * @param repassword String
   * @return StateFlow<User?>
   */
  fun register(username: String, password: String, repassword: String): StateFlow<User?> =
    callBaseRequest(
      { scope, errorCall, showLoading ->
        repository.register(
          scope,
          errorCall,
          showLoading,
          username,
          password,
          repassword
        )
      },
      true
    )
}